<template>
	<view class="after_sale">
		<view class="after_sale-item" v-if="list.length" v-for="(item,index) in list" :key="index" @click="goSaleAfter(item.order_after_id)">
			<image mode="aspectFit" :src="item.goods.image_middle"></image>
			<view class="after_sale-item-info">
				<view class="after_sale-item-tit">{{item.goods.goods_name}}</view>
				<view class="after_sale-item-no">订单编号：{{item.order_sn}}</view>
				<view class="after_sale-item-tag">
					<text class="status-1" v-if="item.status==0">待处理</text>
					<text class="status-1" v-if="item.status==1">处理中</text>
					<text class="status-2" v-if="item.status==2">已处理</text>
					<text class="status-3" v-if="item.status==3">已拒绝</text>
					<text class="change" @click.stop="change(item.order_after_id)" v-if="item.status < 2">修改</text>
				</view>
			</view>
		</view>
		<pt-nothing
			text="暂无售后" 
			:fixed="true" 
			v-if="noData" 
			icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
		</pt-nothing>
		
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" v-if="list.length > 5" />
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noData: false,
				more: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				list: [],
				page: 0,
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				let data = {
					limit: 10,
					page: this.page,
					user_id: uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).user_id:''
				}
				this.$u.apiWei.saleList(data).then(res => {
					if (res.datas.length == 10) {
						this.more = true
					} else {
						this.more = false
					}
					res.datas.forEach((item) => {
						this.list.push(item)
					})
					if (this.list.length == 0 && this.page == 0) this.noData = true
				})

			},
			goSaleAfter(order_after_id) {
				uni.navigateTo({
					animationDuration: 500,
					url: '/my/my-order/after_sale_detail/after_sale_detail?order_after_id=' + order_after_id
				})
			},
			change(order_after_id) {
				uni.navigateTo({
					animationDuration: 500,
					url: '/my/my-order/after_sale_form/after_sale_form?order_after_id=' + order_after_id
				})
			},
			onReachBottom() {
				this.status = 'loading';
				setTimeout(() => {
					this.status = 'nomore';
				}, 1000)
				if (!this.more) return;
				this.page++;
				this.init()
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9F9F9;
	}

	.after_sale-item {
		margin: 20rpx;
		padding: 20rpx;
		background-color: #FFF;
		display: flex;
		align-items: center;
	}

	.after_sale-item image {
		width: 176rpx;
		height: 176rpx;
		border-radius: 8rpx;
		background-color: #EEE;
		margin-right: 20rpx;
	}

	.after_sale-item-tit {
		font-size: 28rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.after_sale-item-no {
		font-size: 24rpx;
		color: #999;
		margin: 20rpx 0;
	}

	.after_sale-item-tag text {
		display: inline-block;
		height: 44rpx;
		border-radius: 8rpx;
		line-height: 44rpx;
		padding: 0 20rpx;
		font-size: 22rpx;
	}

	.status-1 {
		background: rgba(239, 130, 0, 0.06);
		color: #EF8200;
	}

	.status-2 {
		background: rgba(31, 115, 244, 0.06);
		color: #2074F4;
	}

	.status-3 {
		background: rgba(255, 0, 0, 0.06);
		color: rgba(255, 0, 0, 1);
	}

	.change {
		background: rgba(239, 130, 0, 1);
		color: #FFF;
		margin-left: 20rpx;
	}
</style>
